/*
* ATmega128.c
*
* Created: 2/28/2012 4:06:39 PM
*  Author: albert
*/

#ifndef F_CPU
#define F_CPU 14745600UL
#endif

#include <avr/io.h>
#include <util/delay.h>
#include "atmega128_usart.h"
#include "Xbee.h"
#include "Timer.h"
#include "Camera_LS_Y201.h"
#include "Communication_protocal.h"
#include "GlobalDefinitions.h"
#include "spi.h"
#include "led.h"


int main(void)
{
	SPI_MasterInit ();
	_delay_ms(250);
	//======= Variable initial ======
	//xbee_usart_high_speed=1;
	//usart_mode=1;
	//timer_enable=0;
	//===============================
	USART_INIT(xbee_usart_num, usart_mode,BAUDRATE_9600);
	USART_INIT(camera_usart_num, usart_mode,BAUDRATE_38400);
	if (usart_mode == 1)
	sei();
	// Enable the Global Interrupt Enable flag so that interrupts can be processed
	volatile char setup_pass = 0;
	timer_enable = 1;
	do
	{
		if (Xbee_config_init() != 1)
		setup_pass = 1;
		if (Camera_Reset() != 1)
		setup_pass = 1;
		if (Camera_Compression_ratio() != 1)
		setup_pass = 1;
		if (Camera_image_size() != 1)
		setup_pass = 1;
	}
	while (setup_pass);
	Timer1_clear();
	led_toggle(LED_ALL);
	while (Communication_test() != 1)
	;
	
	while (1)
	{
		//led_toggle(LED1);
		// led_toggle(LED_ALL);
		TaskSwitch();
	}
	
}
